package logic

import (
	"context"
	"useryk/userrpc/userrpc"

	"useryk/api/internal/svc"
	"useryk/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProductAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductAddLogic {
	return &ProductAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProductAddLogic) ProductAdd(req *types.ProductAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	productadd, err := l.svcCtx.UserRpc.ProductAdd(l.ctx, &userrpc.ProductAddRequest{
		Categorieid:  req.Categorieid,
		Num:          req.Num,
		Name:         req.Name,
		Categorienum: req.Categorienum,
		Productprice: req.Productprice,
		Costprice:    req.Costprice,
		Image:        req.Image,
	})
	if err != nil {
		return &types.Response{
			Code:    0,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "产品添加成功",
		Data:    productadd,
	}, nil
}
